/*
 * @Author       : Atonidas
 * @LastEditors  : Atonidas
 * @LastEditTime : 2024-01-18 09:12:18
 * @FilePath     : \Mini Ray LCD\LCD\lcd_BSP.h
 * @Description  :
 */
#ifndef __LCD_BSP_H
#define __LCD_BSP_H

#include "Init/lcd_drive.h"
#include "Draw/lcd.h"

#define ST7735    0
#define ST7789    1
#define GC9A01    2
#define GC9307    3

#define TYPE_096A 0
#define TYPE_096B 1
#define TYPE_105  2
#define TYPE_114  3
#define TYPE_240  4
#define TYPE_172  5

//-----------------LCD参数设置----------------

#define LCD_DRIVE      GC9307
#define LCD_TYPE       TYPE_172


#define COLOR_TOGGLE 1 

#define USE_HORIZONTAL 3 // 设置横屏或者竖屏显示 0或1为竖屏 2或3为横屏

#if LCD_TYPE == TYPE_096A
#define DET_X    0x1A
#define DET_Y    0x01
#define SCREEN_H 80
#define SCREEN_W 160

#elif LCD_TYPE == TYPE_096B
#define DET_X    0x18
#define DET_Y    0x00
#define SCREEN_H 80
#define SCREEN_W 160

#elif LCD_TYPE == TYPE_105
#define DET_X    0x3c
#define DET_Y    0x00
#define SCREEN_H 120
#define SCREEN_W 240

#elif LCD_TYPE == TYPE_114
#define DET_X    0x35
#define DET_Y    0x28
#define SCREEN_H 135
#define SCREEN_W 240

#elif LCD_TYPE == TYPE_240
#define DET_X    0x00
#define DET_Y    0x00
#define SCREEN_H 240
#define SCREEN_W 320

#elif LCD_TYPE == TYPE_172
#define DET_X    0x22
#define DET_Y    0x00
#define SCREEN_H 172
#define SCREEN_W 320
#endif

#if USE_HORIZONTAL == 0 || USE_HORIZONTAL == 1
#define LCD_W SCREEN_H
#define LCD_H SCREEN_W

#else
#define LCD_W SCREEN_W
#define LCD_H SCREEN_H
#endif

//-----------------LCD端口定义----------------
#include "main.h"
#include "spi.h"
#include "tim.h"

#define LCD_SPI        hspi1
// #define LCD_BLK_Iint() HAL_TIM_PWM_Start(&htim16, TIM_CHANNEL_1)
// #define LCD_SET_BLK(a) __HAL_TIM_SetCompare(&htim16, TIM_CHANNEL_1, (a))

#define LCD_RES_Clr()  HAL_GPIO_WritePin(LCD_RES_GPIO_Port, LCD_RES_Pin, 0) // RES
#define LCD_RES_Set()  HAL_GPIO_WritePin(LCD_RES_GPIO_Port, LCD_RES_Pin, 1)

#define LCD_DC_Clr()   HAL_GPIO_WritePin(LCD_DC_GPIO_Port, LCD_DC_Pin, 0) // DC
#define LCD_DC_Set()   HAL_GPIO_WritePin(LCD_DC_GPIO_Port, LCD_DC_Pin, 1)

#define LCD_CS_Clr()   HAL_GPIO_WritePin(LCD_CS_GPIO_Port, LCD_CS_Pin, 0) // CS
#define LCD_CS_Set()   HAL_GPIO_WritePin(LCD_CS_GPIO_Port, LCD_CS_Pin, 1)

// #define LCD_BLK_Clr() HAL_GPIO_WritePin(LCD_BLK_GPIO_Port, LCD_BLK_Pin, 0) // BLK
// #define LCD_BLK_Set() HAL_GPIO_WritePin(LCD_BLK_GPIO_Port, LCD_BLK_Pin, 1)

// // 画笔颜色
#if COLOR_TOGGLE == 0
#define WHITE      0xFFFF
#define BLACK      0x0000
#define BLUE       0x001F
#define BRED       0xF81F
#define GRED       0xFFE0
#define GBLUE      0x07FF
#define RED        0xF800
#define MAGENTA    0xF81F
#define GREEN      0x07E0
#define CYAN       0x7FFF
#define YELLOW     0xFFE0
#define BROWN      0xBC40
#define BRRED      0xFC07
#define GRAY       0x8430
#define DARKBLUE   0x01CF
#define LIGHTBLUE  0x7D7C
#define GRAYBLUE   0x5458
#define LIGHTGREEN 0x841F
#define LGRAY      0xC618
#define LGRAYBLUE  0xA651
#define LBBLUE     0x2B12

#else
#define WHITE      0x0000
#define BLACK      0xFFFF
#define BLUE       0xFFE0
#define BRED       0x07E0
#define GRED       0x001F
#define GBLUE      0xF800
#define RED        0x07FF
#define MAGENTA    0x07E0
#define GREEN      0xF81F
#define CYAN       0x8000
#define YELLOW     0x001F
#define BROWN      0x43BF
#define BRRED      0x03F8
#define GRAY       0x7BCC
#define DARKBLUE   0xFE30
#define LIGHTBLUE  0x8283
#define GRAYBLUE   0xABA7
#define LIGHTGREEN 0x7BE0
#define LGRAY      0x39E7
#define LGRAYBLUE  0x5AAE
#define LBBLUE     0xD4ED
#endif

#endif